<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class laporan extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->isLogin();
		$this->num_post=10;		
		$this->load->model("master/master_tapel");
		$this->load->model("master/master_komponen"); 
		$this->load->model("master/master_siswa"); 
		$this->load->model("master/master_lembaga"); 
		$this->load->model("master/master_kelas"); 
		$this->load->model("master/master_set_sekali"); 
		$this->load->model("pembayaran_sekali_model"); 
		$this->load->model("pembayaran_bulanan_model"); 
		$this->load->model("pembayaran_bebas_model"); 
		$this->load->model("pembayaran_tahunan_model");
		//require_once 'Spreadsheet/Excel/Writer.php';		
	}

	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}
	
	function get_periode_tapel($id_tapel){
		$periode=$this->master_tapel->get_periode_tapel($id_tapel);
		foreach($periode as $val){
			$list_periode[$val['id']]=konvert_periode($val['periode']);
		}
		$js='class="form-control form-elba input-sm" id="periode"';
		echo form_dropdown('periode',$list_periode,set_value('periode'),$js);
	}
	
	function get_periode_tapel_awal($id_tapel){
		$periode=$this->master_tapel->get_periode_tapel($id_tapel);
		foreach($periode as $val){
			$list_periode[$val['id']]=konvert_periode($val['periode']);
		}
		$js='class="form-control form-elba input-sm" id="periode_awal"';
		echo form_dropdown('periode_awal',$list_periode,set_value('periode'),$js);
	}
	
	function get_periode_tapel_akhir($id_tapel){
		$periode=$this->master_tapel->get_periode_tapel($id_tapel);
		foreach($periode as $val){
			$list_periode[$val['id']]=konvert_periode($val['periode']);
		}
		$js='class="form-control form-elba input-sm" id="periode_akhir"';
		echo form_dropdown('periode_akhir',$list_periode,set_value('periode'),$js);
	}
	
	function get_kelas_lembaga($id_lembaga,$tapel=null){
		if($tapel==null){
			$tapel_aktif=$this->master_tapel->get_tapel_aktif();
			$id_tapel=$tapel_aktif['id_mr_th_ajaran'];
		}else{
			$id_tapel=$tapel;
		}
		$kelas=$this->master_kelas->get_kelas_lembaga($id_lembaga,$id_tapel);
		$list_kelas['all']='Semua';
		foreach($kelas as $val){
			$list_kelas[$val['id_mr_kelas']]=$val['kelas'];
		}
		$js='class="form-control form-elba input-sm" id="kelas"';
		echo form_dropdown('kelas',$list_kelas,set_value('kelas'),$js);
	}
	
	function laporan_pembayaran(){
		$tapel_aktif=$this->master_tapel->get_tapel_aktif();
		$data['detail_tapel']=$this->master_tapel->detail($tapel_aktif['id_mr_th_ajaran']);
		//print_r( $data['detail_tapel']);
		$data['lembaga']['all']='Semua';
		$lembaga=$this->master_lembaga->get_all();
		foreach($lembaga as $val){
			$data['lembaga'][$val['id_lembaga']]=$val['nama_lembaga'];
		}
		$tapel=$this->master_tapel->tapel_semua();
		foreach($tapel as $val){
			$data['tapel'][$val['id_mr_th_ajaran']]=$val['th_ajaran'];
		}
		$data['main_view']='laporan/view_laporan_pembayaran';
		$periode=$this->master_tapel->get_list_periode();
		$data['periode_aktif']=$this->master_tapel->get_periode_aktif();
		foreach($periode as $val){
			$data['list_periode'][$val['id']]=konvert_periode($val['periode']);
		}
		$data['list_kelas']['all']='Semua';
		$this->load->view('index',$data);
	}
	
	function laporan_tagihan(){
		$data['main_view']='laporan/view_laporan_tagihan';
		$tapel=$this->master_tapel->tapel_semua();
		$data['lembaga']['all']='Semua';
		$lembaga=$this->master_lembaga->get_all();
		foreach($lembaga as $val){
			$data['lembaga'][$val['id_lembaga']]=$val['nama_lembaga'];
		}
		$data['list_kelas']['all']='Semua';
		$tapel_aktif=$this->master_tapel->get_tapel_aktif();
		$data['detail_tapel']=$this->master_tapel->detail($tapel_aktif['id_mr_th_ajaran']);
		foreach($tapel as $val){
			$data['tapel'][$val['id_mr_th_ajaran']]=$val['th_ajaran'];
		}
		$data['periode_aktif']=$this->master_tapel->get_periode_aktif();
		$periode=$this->master_tapel->get_list_periode();
		foreach($periode as $val){
			$data['list_periode'][$val['id']]=konvert_periode($val['periode']);
		}
		$this->load->view('index',$data);
	}
	
	function hasil_laporan_tagihan(){
		$lembaga=$this->input->post('lembaga');
		$kelas=$this->input->post('kelas');
		$tapel=$this->input->post('tapel');
		$excel=$this->input->post('excel');
		$periode_awal=$this->input->post('periode_awal');
		$periode_akhir=$this->input->post('periode_akhir');
		
		if(!empty($excel)){
			//export excel
			$this->excel_tagihan($lembaga,$kelas,$tapel,$periode_awal,$periode_akhir);
			exit;
		}
		
		$detail_awal=$this->master_tapel->detail_periode($periode_awal);
		$detail_akhir=$this->master_tapel->detail_periode($periode_akhir);
		$str_periode=konvert_periode($detail_awal['periode']).' s/d '.konvert_periode($detail_akhir['periode']);
		$list_komp=$this->master_komponen->get_all_komp_rutin();
		foreach($list_komp as $key=>$val){
			$arr_komp['komp_'.$val['id_komp']]=$val['nama_komp'];
			$arr_jumlah['komp_'.$val['id_komp']]=0;
		}
		
		//$data_siswa=$this->master_siswa->get_all_data();
		$data_siswa=$this->master_siswa->get_data_by_kelas($lembaga,$kelas,$tapel);
		$laporan=array();
		foreach($data_siswa as $key=>$val){
			$laporan[$key]=$val;
			$jumlah_kanan=0;
			foreach($list_komp as $key_komp=>$val_komp){
				$jml_komp=$this->get_tunggakan_komp($val['nis'],$val_komp['id_komp'],$tapel,$val_komp['jenis_komp'],$periode_awal,$periode_akhir);
				$laporan[$key]['komp_'.$val_komp['id_komp']]=$jml_komp;
				$arr_jumlah['komp_'.$val_komp['id_komp']]+=$jml_komp;
				$jumlah_kanan+=$jml_komp;
			}
			$laporan[$key]['total_kanan']=$jumlah_kanan;
		}
		$data['arr_komp']=$arr_komp;
		$data['laporan']=$laporan;
		$data['arr_jumlah']=$arr_jumlah;
		if($kelas=='all'){
			$str_kelas='Semua';
		}else{
			$det_kelas=$this->master_kelas->get_detail($kelas);
			$str_kelas=$det_kelas['kelas'];
		}
		if($lembaga=='all'){
			$str_lembaga="Semua";
		}else{
			$det_lembaga=$this->master_lembaga->detail($lembaga);
			$str_lembaga=$det_lembaga['nama_lembaga'];
		}
		
		$data['str_lembaga']=$str_lembaga;
		$data['str_kelas']=$str_kelas;
		$det_tapel=$this->master_tapel->detail($tapel);
		$data['str_tapel']=$det_tapel['th_ajaran'];
		$data['str_periode']=$str_periode;
		$this->load->view('laporan/laporan_tagihan',$data);
	}
	
	function excel_tagihan($lembaga,$kelas,$tapel,$periode_awal,$periode_akhir){
		$detail_awal=$this->master_tapel->detail_periode($periode_awal);
		$detail_akhir=$this->master_tapel->detail_periode($periode_akhir);
		$str_periode=konvert_periode($detail_awal['periode']).' s/d '.konvert_periode($detail_akhir['periode']);
		$list_komp=$this->master_komponen->get_all_komp_rutin();
		foreach($list_komp as $key=>$val){
			$arr_komp['komp_'.$val['id_komp']]=$val['nama_komp'];
			$arr_jumlah['komp_'.$val['id_komp']]=0;
		}
		
		//$data_siswa=$this->master_siswa->get_all_data();
		$data_siswa=$this->master_siswa->get_data_by_kelas($lembaga,$kelas,$tapel);
		$laporan=array();
		foreach($data_siswa as $key=>$val){
			$laporan[$key]=$val;
			$jumlah_kanan=0;
			foreach($list_komp as $key_komp=>$val_komp){
				$jml_komp=$this->get_tunggakan_komp($val['nis'],$val_komp['id_komp'],$tapel,$val_komp['jenis_komp'],$periode_awal,$periode_akhir);
				$laporan[$key]['komp_'.$val_komp['id_komp']]=$jml_komp;
				$arr_jumlah['komp_'.$val_komp['id_komp']]+=$jml_komp;
				$jumlah_kanan+=$jml_komp;
			}
			$laporan[$key]['total_kanan']=$jumlah_kanan;
		}
		//$data['arr_komp']=$arr_komp;
		//$data['laporan']=$laporan;
		//$data['arr_jumlah']=$arr_jumlah;
		if($kelas=='all'){
			$str_kelas='Semua';
		}else{
			$det_kelas=$this->master_kelas->get_detail($kelas);
			$str_kelas=$det_kelas['kelas'];
		}
		if($lembaga=='all'){
			$str_lembaga="Semua";
		}else{
			$det_lembaga=$this->master_lembaga->detail($lembaga);
			$str_lembaga=$det_lembaga['nama_lembaga'];
		}
		
		//$data['str_lembaga']=$str_lembaga;
		//$data['str_kelas']=$str_kelas;
		$det_tapel=$this->master_tapel->detail($tapel);
		$str_tapel=$det_tapel['th_ajaran'];
		//$data['str_periode']=$str_periode;
		
		//membuat excel
		
		$workbook = new Spreadsheet_Excel_Writer();
		// Membuat format cell header kolom / huruf tebal + background color
		$cellHeaderFormat =& $workbook->addFormat();
		$cellHeaderFormat->setPattern(2); // pola background
		$cellHeaderFormat->setAlign('center'); // rata tengah horizontal
		$cellHeaderFormat->setVAlign('vcenter'); // rata tengah vertikal
		$cellHeaderFormat->setSize('9');  // ukuran font
		$cellHeaderFormat->setBgColor(5); // setting warna background
		$cellHeaderFormat->setFgColor(1); // setting warna huruf
		$cellHeaderFormat->setBold();
		$cellHeaderFormat->setBottom(1);//thick
		$cellHeaderFormat->setTop(1);//thick
		$cellHeaderFormat->setRight(1);//thick
		$cellHeaderFormat->setLeft(1);//thick
		
		
		// Membuat format cell string
		$cellStringFormat =& $workbook->addFormat();
		$cellStringFormat->setAlign('left'); // rata kiri horizontal
		$cellStringFormat->setVAlign('vcenter'); // rata tengah vertikal
		$cellStringFormat->setSize('9');  // ukuran font
		$cellStringFormat->setBottom(1);//thick
		$cellStringFormat->setTop(1);//thick
		$cellStringFormat->setRight(1);//thick
		$cellStringFormat->setLeft(1);//thick
		
		$cellJudul =& $workbook->addFormat();
		$cellJudul->setAlign('left'); // rata kiri horizontal
		$cellJudul->setVAlign('vcenter'); // rata tengah vertikal
		$cellJudul->setSize('14');  // ukuran font
		
		$cellJudulCurrency =& $workbook->addFormat();
		$cellJudulCurrency->setAlign('right'); // rata kiri horizontal
		$cellJudulCurrency->setVAlign('vcenter'); // rata tengah vertikal
		$cellJudulCurrency->setSize('14');  // ukuran font
		$cellJudulCurrency->setNumFormat(4);
		
		// Membuat format cell Currency/Float
		$cellCurrencyFormat =& $workbook->addFormat();
		$cellCurrencyFormat->setAlign('right');
		$cellCurrencyFormat->setVAlign('vcenter');
		$cellCurrencyFormat->setSize('9');
		$cellCurrencyFormat->setNumFormat(4); // setting untuk format currency
		$cellCurrencyFormat->setBottom(1);//thick
		$cellCurrencyFormat->setTop(1);//thick
		$cellCurrencyFormat->setRight(1);//thick
		$cellCurrencyFormat->setLeft(1);//thick
		// Membuat format cell nomor Integer
		$cellIntFormat =& $workbook->addFormat();
		$cellIntFormat->setAlign('right');
		$cellIntFormat->setVAlign('vcenter');
		$cellIntFormat->setSize('9');
		$cellIntFormat->setNumFormat(1); // setting untuk format integer
		$cellIntFormat->setBottom(1);//thick
		$cellIntFormat->setTop(1);//thick
		$cellIntFormat->setRight(1);//thick
		$cellIntFormat->setLeft(1);//thick
		
		$worksheet =& $workbook->addWorksheet();
		
		$worksheet->write(0, 0, "Laporan Tagihan Pembayaran Tahun Pelajaran ".$str_tapel, $cellJudul); 
		$worksheet->write(1, 0, "Periode ".$str_periode, $cellJudul); 
		$worksheet->write(2, 0, "Lembaga : ".$str_lembaga, $cellJudul); 
		$worksheet->write(3, 0, "Kelas : ".$str_kelas, $cellJudul); 
		$worksheet->writeRow(5, 0, array("No","Nama Siswa","NVA","NIS"), $cellHeaderFormat);
		$cols=4;
		foreach($arr_komp as $val_komp){
			//echo "<th scope=col class=rounded>$tanggal</th>";
			$worksheet->write(5, $cols, $val_komp, $cellHeaderFormat); 
			$cols++;
		}
		$worksheet->write(5, $cols, "Total", $cellHeaderFormat); 
		$rows=6;
		
		$total=0;
		if(isset($laporan)){
			$no=1;
			
			foreach($laporan as $key=>$val){
				$worksheet->write($rows, 0, $no, $cellStringFormat);
				$worksheet->write($rows, 1, $val['nm_lengkap'], $cellStringFormat);
				$worksheet->write($rows, 2, $val['nis'], $cellStringFormat);
				$worksheet->write($rows, 3, $val['nva'], $cellStringFormat);
				$cols=4;
				foreach($arr_komp as $key_komp => $val_komp){
					//echo "<td align='right'>".number_format($val[$key_komp],0,",",".")."</td>";
					$worksheet->write($rows, $cols, $val[$key_komp], $cellCurrencyFormat);
					$cols++;
				}
				$worksheet->write($rows, $cols, $val['total_kanan'], $cellCurrencyFormat); 
				$total+=$val['total_kanan'];
				$no++;
				$rows++;
			}
			$worksheet->write($rows, 0, "Total", $cellStringFormat);
			$cols=4;
			if(isset($arr_jumlah)){
				foreach($arr_jumlah as $val){
					$worksheet->write($rows, $cols, $val, $cellCurrencyFormat); 
					$cols++;
				}
			}
			$worksheet->write($rows, $cols, $total, $cellCurrencyFormat); 
		}
		$workbook->send('laporan_tagihan.xls');
		// mwnghapus workbook dari memory
		$workbook->close();

	}
	
	function excel_laporan_pembayaran($lembaga,$kelas,$tgl_awal,$tgl_akhir){
		$tapel_aktif=$this->master_tapel->get_tapel_aktif();
		$id_tapel=$tapel_aktif['id_mr_th_ajaran'];
		//$detail_periode=$this->master_tapel->detail_periode($periode);
		$list_komp=$this->master_komponen->get_all();
		foreach($list_komp as $key=>$val){
			$arr_komp['komp_'.$val['id_komp']]=$val['nama_komp'];
			$arr_jumlah['komp_'.$val['id_komp']]=0;
		}
		
		$data_siswa=$this->master_siswa->get_data_by_kelas($lembaga,$kelas,$id_tapel);
		$laporan=array();
		foreach($data_siswa as $key=>$val){
			$laporan[$key]=$val;
			$jumlah_kanan=0;
			foreach($list_komp as $key_komp=>$val_komp){
				$jml_komp=$this->get_bayar_komp($val['nis'],$val_komp['id_komp'],$tgl_awal,$tgl_akhir,$val_komp['jenis_komp']);
				$laporan[$key]['komp_'.$val_komp['id_komp']]=$jml_komp;
				$arr_jumlah['komp_'.$val_komp['id_komp']]+=$jml_komp;
				$jumlah_kanan+=$jml_komp;
			}
			$laporan[$key]['total_kanan']=$jumlah_kanan;
		}
		//echo "<pre>";
		//$data['arr_komp']=$arr_komp;
		//$data['laporan']=$laporan;
		//$data['arr_jumlah']=$arr_jumlah;
		if($kelas=='all'){
			$str_kelas='Semua';
		}else{
			$det_kelas=$this->master_kelas->get_detail($kelas);
			$str_kelas=$det_kelas['kelas'];
		}
		if($lembaga=='all'){
			$str_lembaga="Semua";
		}else{
			$det_lembaga=$this->master_lembaga->detail($lembaga);
			$str_lembaga=$det_lembaga['nama_lembaga'];
		}
		
		//$data['str_lembaga']=$str_lembaga;
		//$data['str_kelas']=$str_kelas;
		$str_periode=tgl_indonesia($tgl_awal).' s/d '.tgl_indonesia($tgl_akhir);
		//membuat excel
		
		$workbook = new Spreadsheet_Excel_Writer();
		// Membuat format cell header kolom / huruf tebal + background color
		$cellHeaderFormat =& $workbook->addFormat();
		$cellHeaderFormat->setPattern(2); // pola background
		$cellHeaderFormat->setAlign('center'); // rata tengah horizontal
		$cellHeaderFormat->setVAlign('vcenter'); // rata tengah vertikal
		$cellHeaderFormat->setSize('9');  // ukuran font
		$cellHeaderFormat->setBgColor(5); // setting warna background
		$cellHeaderFormat->setFgColor(1); // setting warna huruf
		$cellHeaderFormat->setBold();
		$cellHeaderFormat->setBottom(1);//thick
		$cellHeaderFormat->setTop(1);//thick
		$cellHeaderFormat->setRight(1);//thick
		$cellHeaderFormat->setLeft(1);//thick
		
		
		// Membuat format cell string
		$cellStringFormat =& $workbook->addFormat();
		$cellStringFormat->setAlign('left'); // rata kiri horizontal
		$cellStringFormat->setVAlign('vcenter'); // rata tengah vertikal
		$cellStringFormat->setSize('9');  // ukuran font
		$cellStringFormat->setBottom(1);//thick
		$cellStringFormat->setTop(1);//thick
		$cellStringFormat->setRight(1);//thick
		$cellStringFormat->setLeft(1);//thick
		
		$cellJudul =& $workbook->addFormat();
		$cellJudul->setAlign('left'); // rata kiri horizontal
		$cellJudul->setVAlign('vcenter'); // rata tengah vertikal
		$cellJudul->setSize('14');  // ukuran font
		
		$cellJudulCurrency =& $workbook->addFormat();
		$cellJudulCurrency->setAlign('right'); // rata kiri horizontal
		$cellJudulCurrency->setVAlign('vcenter'); // rata tengah vertikal
		$cellJudulCurrency->setSize('14');  // ukuran font
		$cellJudulCurrency->setNumFormat(4);
		
		// Membuat format cell Currency/Float
		$cellCurrencyFormat =& $workbook->addFormat();
		$cellCurrencyFormat->setAlign('right');
		$cellCurrencyFormat->setVAlign('vcenter');
		$cellCurrencyFormat->setSize('9');
		$cellCurrencyFormat->setNumFormat(4); // setting untuk format currency
		$cellCurrencyFormat->setBottom(1);//thick
		$cellCurrencyFormat->setTop(1);//thick
		$cellCurrencyFormat->setRight(1);//thick
		$cellCurrencyFormat->setLeft(1);//thick
		// Membuat format cell nomor Integer
		$cellIntFormat =& $workbook->addFormat();
		$cellIntFormat->setAlign('right');
		$cellIntFormat->setVAlign('vcenter');
		$cellIntFormat->setSize('9');
		$cellIntFormat->setNumFormat(1); // setting untuk format integer
		$cellIntFormat->setBottom(1);//thick
		$cellIntFormat->setTop(1);//thick
		$cellIntFormat->setRight(1);//thick
		$cellIntFormat->setLeft(1);//thick
		
		$worksheet =& $workbook->addWorksheet();
		
		$worksheet->write(0, 0, "Laporan Pembayaran Periode ".$str_periode, $cellJudul); 
		$worksheet->write(1, 0, "Lembaga : ".$str_lembaga, $cellJudul); 
		$worksheet->write(2, 0, "Kelas : ".$str_kelas, $cellJudul); 
		$worksheet->writeRow(4, 0, array("No","Nama Siswa","NVA","NIS"), $cellHeaderFormat);
		$cols=4;
		foreach($arr_komp as $val_komp){
			//echo "<th scope=col class=rounded>$tanggal</th>";
			$worksheet->write(4, $cols, $val_komp, $cellHeaderFormat); 
			$cols++;
		}
		$worksheet->write(4, $cols, "Total", $cellHeaderFormat); 
		$rows=5;
		
		$total=0;
		if(isset($laporan)){
			$no=1;
			
			foreach($laporan as $key=>$val){
				$worksheet->write($rows, 0, $no, $cellStringFormat);
				$worksheet->write($rows, 1, $val['nm_lengkap'], $cellStringFormat);
				$worksheet->write($rows, 2, $val['nis'], $cellStringFormat);
				$worksheet->write($rows, 3, $val['nva'], $cellStringFormat);
				$cols=4;
				foreach($arr_komp as $key_komp => $val_komp){
					//echo "<td align='right'>".number_format($val[$key_komp],0,",",".")."</td>";
					$worksheet->write($rows, $cols, $val[$key_komp], $cellCurrencyFormat);
					$cols++;
				}
				$worksheet->write($rows, $cols, $val['total_kanan'], $cellCurrencyFormat); 
				$total+=$val['total_kanan'];
				$no++;
				$rows++;
			}
			$worksheet->write($rows, 0, "Total", $cellStringFormat);
			$cols=4;
			if(isset($arr_jumlah)){
				foreach($arr_jumlah as $val){
					$worksheet->write($rows, $cols, $val, $cellCurrencyFormat); 
					$cols++;
				}
			}
			$worksheet->write($rows, $cols, $total, $cellCurrencyFormat); 
		}
		$workbook->send('laporan_pembayaran.xls');
		// mwnghapus workbook dari memory
		$workbook->close();
	}
	
	function hasil_laporan(){
		$tgl_awal = $this->input->post('tgl_awal');
		$tgl_awal = date("Y-m-d", strtotime ($tgl_awal));
		
		$tgl_akhir = $this->input->post('tgl_akhir');
		$tgl_akhir = date("Y-m-d", strtotime ($tgl_akhir));
		
		$excel=$this->input->post('excel');
		
		$lembaga=$this->input->post('lembaga');
		$kelas=$this->input->post('kelas');
		
		if(!empty($excel)){
			//export excel
			$this->excel_laporan_pembayaran($lembaga,$kelas,$tgl_awal,$tgl_akhir);
			exit;
		}
		
		$tapel_aktif=$this->master_tapel->get_tapel_aktif();
		$id_tapel=$tapel_aktif['id_mr_th_ajaran'];
		//$detail_periode=$this->master_tapel->detail_periode($periode);
		$list_komp=$this->master_komponen->get_all();
		foreach($list_komp as $key=>$val){
			$arr_komp['komp_'.$val['id_komp']]=$val['nama_komp'];
			$arr_jumlah['komp_'.$val['id_komp']]=0;
		}
		
		$data_siswa=$this->master_siswa->get_data_by_kelas($lembaga,$kelas,$id_tapel);
		$laporan=array();
		foreach($data_siswa as $key=>$val){
			$laporan[$key]=$val;
			$jumlah_kanan=0;
			foreach($list_komp as $key_komp=>$val_komp){
				$jml_komp=$this->get_bayar_komp($val['nis'],$val_komp['id_komp'],$tgl_awal,$tgl_akhir,$val_komp['jenis_komp']);
				$laporan[$key]['komp_'.$val_komp['id_komp']]=$jml_komp;
				$arr_jumlah['komp_'.$val_komp['id_komp']]+=$jml_komp;
				$jumlah_kanan+=$jml_komp;
			}
			$laporan[$key]['total_kanan']=$jumlah_kanan;
		}
		//echo "<pre>";
		$data['arr_komp']=$arr_komp;
		$data['laporan']=$laporan;
		$data['arr_jumlah']=$arr_jumlah;
		if($kelas=='all'){
			$str_kelas='Semua';
		}else{
			$det_kelas=$this->master_kelas->get_detail($kelas);
			$str_kelas=$det_kelas['kelas'];
		}
		if($lembaga=='all'){
			$str_lembaga="Semua";
		}else{
			$det_lembaga=$this->master_lembaga->detail($lembaga);
			$str_lembaga=$det_lembaga['nama_lembaga'];
		}
		
		$data['str_lembaga']=$str_lembaga;
		$data['str_kelas']=$str_kelas;
		$data['str_periode']=tgl_indonesia($tgl_awal).' s/d '.tgl_indonesia($tgl_akhir);
		$this->load->view('laporan/laporan_pembayaran',$data);
	}
	
	function get_sisa_pembayaran_sekali($nis,$id_komp){
		$detail_siswa=$this->master_siswa->detail($nis);
		$tagihan=$this->pembayaran_sekali_model->get_tagihan_komponen($nis,$id_komp,$detail_siswa[0]->id_tapel_masuk);
		//$nom_tagihan=$tagihan['nominal'];
		$bayar=$this->pembayaran_sekali_model->get_bayar($nis,$id_komp);
		$sisa=$tagihan-$bayar;
		return $sisa;
	}
	function get_tunggakan_komp($nis,$id_komp,$id_tapel,$jenis_komp,$periode_awal,$periode_akhir){
		switch($jenis_komp){
		case "tahunan":
			$hasil_komp=$this->pembayaran_tahunan_model->get_total_tagihan($nis,$id_tapel,$id_komp);
			break;
		case "sekali":
			$hasil_komp=$this->get_sisa_pembayaran_sekali($nis,$id_komp);
			break;
		case "bulanan":
			$hasil_komp=$this->pembayaran_bulanan_model->get_total_tagihan($nis,$id_komp,$periode_awal,$periode_akhir);
			break;
		}
		
		return $hasil_komp;
	}
	
	function get_bayar_komp($nis,$id_komp,$tgl_awal,$tgl_akhir,$jenis_komp){
		//$detail_periode=$this->master_tapel->detail_periode($periode);
		switch($jenis_komp){
		case "sekali":
			$hasil_komp=$this->pembayaran_sekali_model->get_bayar_bulan($nis,$id_komp,$tgl_awal,$tgl_akhir);
			break;
		case "tahunan":
			$hasil_komp=$this->pembayaran_tahunan_model->get_bayar_bulan($nis,$id_komp,$tgl_awal,$tgl_akhir);
			break;
		case "bulanan":
			$hasil_komp=$this->pembayaran_bulanan_model->get_bayar_bulanan($nis,$id_komp,$tgl_awal,$tgl_akhir);
			break;
		case "bebas":
			$hasil_komp=$this->pembayaran_bebas_model->get_bayar_bulan($nis,$id_komp,$tgl_awal,$tgl_akhir);
			break;
		}
		return $hasil_komp;
	}

}

?>